Appendix: Uniication Algorithm 5.4 Irrefutable Patterns 5.1 Overloading 5.2 Preserving Polymorphism 4.4 Instances of a Polymorphic Type 4.3 Type Checking an Instruction Sequence 4.1 Type Structure 4.2 Type Interpretation 4 Types for Terms Polymorphic Type Checking by Interpretation of Code

نویسنده

  • Stefan Kahrs
چکیده

In the text, the function unify was used several times, but it has not been deened yet. As mentioned, we need just ordinary rst-order uniication, so we give its deenition here for the sake of completeness. The algorithm uses a simple divide-and-conquer strategy, i.e. it uniies two terms by unifying their subterms and composing the resulting uniiers. unify x (Tvar n) = unify (Tvar n) x unify (Tcon s tl) (Tcon s' tl') = foldr comp (True,,]) (zipWith unify tl tl'), if s=s' unify p q = (False, undef), otherwise zipWith f (a:as) (b:bs) = f a b : zipWith f as bs zipWith f x y = ] The function unify does proper uniication, comp tries to compose the uniiers of the subproblems. It is assumed that each type constructor s has a xed arity a s , i.e. for any (Tcon s ls) the list ls has length a s. This assumption is not really necessary for rst-order uniication, but it is simply true for the languages with which we are concerned. occur n (Tvar m) = n=m occur n (Tcon f ls) = t|t<-ls; occur n t] ~= ] Ordinary uniication of rst order terms requires an occur check, here performed by the function occur. It would be no problem to enrich the approach to cyclic types, i.e. to use trees with nitely many diierent subtrees instead of nite trees, but this is beyond the scope of this paper and is of no signiicance for the approach. comp (True,x)(True,y) = foldr comp1 (True,x) y comp x y = (False,undef), otherwise comp1 x (False,y) = (False,undef) comp1 (n,t) (True,s) = comp (unify t (hd ua)) (True,s), if ua~==] = (True,s), if t'=Tvar n = (False,undef), if occur n t' = (True,(n,t'):s'), otherwise where ua = lookup n s t' = subst s t s' = subst_assoc (n,t')] s The function comp composes two uniiers. An occur check (for comp1) is necessary again, because the type t, the substitute for n, might contain a type variable m, which might be substituted in (True,s) by a type u, which again might contain the type variable n. lookup lab ls = val | (x,val)<-ls; x=lab] subst sub (Tvar n) = hd u, if u~==] = Tvar n, otherwise where u = lookup n sub subst sub (Tcon f ls) = Tcon f (map (subst sub) ls) subst_assoc sub ls = (x,subst …

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Typing deep pattern-matching in presence of polymorphic variants

Polymorphic variants are a well-known feature of the Objective Caml programming language, and they have turned popular since their introduction. They allow structural equality of algebraic type definitions, and code reuse through their polymorphism. Their typing and compilation have been studied in the past, and there are already detailed published works for both2),4). By their very nature, pol...

متن کامل

An Interpretation of Standard ML in Type Theory

We de ne an interpretation of Standard ML into type theory. The interpretation takes the form of a set of elaboration rules reminiscent of the static semantics given in The De nition of Standard ML. In particular, the elaboration rules are given in a relational style, exploiting indeterminacy to avoid over-commitment to speci c implementation techniques. Elaboration consists of identi er scope ...

متن کامل

Polymorphic Type Inference and Semi-Uni cation

In the last ten years declaration-free programming languages with a polymorphic typing discipline (ML, B) have been developed to approximate the exibility and conciseness of dynamically typed languages (LISP, SETL) while retaining the safety and execution e ciency of conventional statically typed languages (Algol68, Pascal). These polymorphic languages can be type checked at compile time, yet a...

متن کامل

Dimension Inference under Polymorphic

Numeric types can be given polymorphic dimension parameters , in order to avoid dimension errors and unit errors. The most general dimensions can be inferred automatically. It has been observed that polymorphic recursion is more important for the dimensions than for the proper types. We show that, under polymorphic recursion, type inference amounts to syntactic semi-uniication of proper types, ...

متن کامل

First-class labels for extensible rows

This paper describes a type system for extensible records and variants with first-class labels; labels are polymorphic and can be passed as arguments. This increases the expressiveness of conventional record calculi significantly, and we show how we can encode intersection types, closed-world overloading, type case, label selective calculi, and first-class messages. We formally motivate the nee...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1992